home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / DCLAP 6d / dclap6d / DBio / DSeqPrint.cpp < prev    next >
Text File  |  1996-07-05  |  55KB  |  2,004 lines

  1. // DSeqPrint.cpp
  2. // d.g.gilbert, 1991-95
  3.  
  4. #define MASKS 1
  5.  
  6. #include "DSequence.h"
  7. #include "DSeqList.h"
  8. #include "DSeqDoc.h"
  9. #include "DSeqPrint.h"
  10. #include "DSeqPrintSubs.h"
  11. #include "DREnzyme.h"
  12.  
  13. #include <ncbi.h>
  14. #include <dgg.h>
  15. #include <Dvibrant.h>
  16. #include <DControl.h>
  17. #include <DDialogText.h>
  18. #include <DWindow.h>
  19. #include <DTableView.h>
  20. #include <DApplication.h>
  21. #include <DTask.h>
  22. #include <DTracker.h>
  23. #include <DMenu.h>
  24. #include <DUtil.h>
  25.  
  26.  
  27.  
  28. #undef TESTZOOM
  29.  
  30.  
  31.  
  32. Global DSeqPrintPrefs* gSeqPrintPrefs = NULL;
  33.  
  34. char* DSeqPrintPrefs::gNameFontName = (char*) "times";
  35. char* DSeqPrintPrefs::gBaseFontName = (char*) "courier";
  36. char* DSeqPrintPrefs::gIndexFontName = (char*) "times";
  37. Nlm_FonT 
  38.             DSeqPrintPrefs::gNameFont = NULL, 
  39.              DSeqPrintPrefs::gBaseFont = NULL, 
  40.           DSeqPrintPrefs::gIndexFont = NULL;
  41. short 
  42.             DSeqPrintPrefs::gNameFontSize = 10, 
  43.             DSeqPrintPrefs::gBaseFontSize = 10, 
  44.             DSeqPrintPrefs::gIndexFontSize = 9,
  45.             DSeqPrintPrefs::gNameStyle = 0,  
  46.             DSeqPrintPrefs::gBaseStyle = 0,  
  47.             DSeqPrintPrefs::gIndexStyle = 0;
  48. Boolean     
  49.             DSeqPrintPrefs::gNameLeft = false,
  50.             DSeqPrintPrefs::gNameRight = true,
  51.             DSeqPrintPrefs::gIndexLeft = true,
  52.             DSeqPrintPrefs::gIndexRight = false,
  53.             DSeqPrintPrefs::gIndexTop = true, 
  54.             DSeqPrintPrefs::gColored = true;
  55.  
  56.     // restmap prefs ..
  57. Boolean  
  58.             DSeqPrintPrefs::gShowComplement = true,
  59.             DSeqPrintPrefs::gThreeLetAA = false,
  60.             DSeqPrintPrefs::gOnlyORF = false,
  61.             DSeqPrintPrefs::gShowAA1 = false,
  62.             DSeqPrintPrefs::gShowAA2 = false,
  63.             DSeqPrintPrefs::gShowAA3 = false,
  64.             DSeqPrintPrefs::gShowCompAA1 = false,
  65.             DSeqPrintPrefs::gShowCompAA2 = false,
  66.             DSeqPrintPrefs::gShowCompAA3 = false,
  67.             DSeqPrintPrefs::gShowAllZymes = false,
  68.             DSeqPrintPrefs::gShowCutpoints = false,
  69.             DSeqPrintPrefs::gShowExcludedCutters = false,
  70.             DSeqPrintPrefs::gShowNoncutters = false;
  71. short    
  72.             DSeqPrintPrefs::gBasesPerLine = 60,
  73. #ifdef WIN_MAC
  74.             DSeqPrintPrefs::gOutFormat = cOutPICT,
  75. #else
  76.             DSeqPrintPrefs::gOutFormat = cOutText,
  77. #endif            
  78.             DSeqPrintPrefs::gREMinCuts = 1, 
  79.             DSeqPrintPrefs::gREMaxCuts = 999;
  80.  
  81.  
  82. char DDrawMapRow::fLinebuf[DDrawMapRow::kMaxLinebuf+1];
  83.  
  84.  
  85.  
  86. // add this to ?? dgg.c
  87. inline void RectRgn(Nlm_RegioN rgn, Nlm_RectPtr r)
  88. {
  89.     Nlm_LoadRectRgn( rgn, r->left, r->top, r->right, r->bottom);
  90. }
  91.  
  92.  
  93. static short gBaseCharWidth = 12;
  94. static short gLineHeight = 12;
  95.  
  96.  
  97. //inline 
  98. static short BaseCharWidth()
  99. {
  100. #ifdef TESTZOOM
  101. #if 1
  102.      gBaseCharWidth= 1;
  103. #else
  104.         // TESTING...
  105.     if (gKeys->shift()) gBaseCharWidth= 1;    else gBaseCharWidth= 12; 
  106.     if (gBaseCharWidth>1) gBaseCharWidth= Nlm_CharWidth('G');
  107. #endif
  108. #else
  109.     gBaseCharWidth= Nlm_CharWidth('G');
  110. #endif
  111.     return gBaseCharWidth;
  112. }
  113.  
  114. //inline 
  115. static short BaseLineHeight()
  116. {
  117.     gLineHeight = Nlm_LineHeight();
  118.     return gLineHeight;
  119. }
  120.  
  121. //inline 
  122. static void BaseDraw( char b)
  123. {
  124. #ifdef TESTZOOM
  125.     if (gBaseCharWidth < 5) {
  126.         Nlm_PoinT pt;
  127.         Nlm_GetPen (&pt);
  128.     Nlm_MoveTo (pt.x, pt.y);
  129.     pt.y -= gLineHeight; //Nlm_LineHeight();
  130.     Nlm_LineTo (pt.x, pt.y);
  131.         }
  132.     else 
  133. #endif
  134.         Nlm_PaintChar(b);
  135. }
  136.  
  137.  
  138.  
  139.  
  140.  
  141. // class DDrawSpacer
  142.  
  143. void DDrawSpacer::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  144. {
  145.     if (fTitle) {
  146.         if (fFont) Nlm_SelectFont(fFont);
  147.         Nlm_MoveTo( r.left, r.bottom-2);
  148.         Nlm_PaintString(fTitle);
  149.         }
  150. }
  151.  
  152. const char* DDrawSpacer::Write( short row, short col, long startitem, long stopitem)
  153.     long  len= Min( kMaxLinebuf, stopitem-startitem);
  154.     Nlm_MemFill(fLinebuf, ' ', len);
  155.     if (fTitle) MemCpy( fLinebuf, fTitle, Min( len, StrLen(fTitle)) );
  156.     fLinebuf[len]= 0;
  157.     return fLinebuf;
  158. }
  159.  
  160.  
  161.  
  162.  
  163. // class DDrawIndexRow 
  164.  
  165. void DDrawIndexRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  166. {  
  167.     short atx, aty, cleft, rowtop;
  168.     short up1, up2, upFont;
  169.     
  170.     if (col>0) startitem += col;
  171.  
  172.     if (fFont) Nlm_SelectFont(fFont);
  173.     cleft= r.left; // add a bit to move over bases
  174.     if (fIsUp) {
  175.         up1= -1;
  176.         up2= -3;
  177.         upFont= -4;
  178.         rowtop= r.bottom - kIndexRise; 
  179.         }
  180.     else {
  181.         up1= 1;
  182.         up2= 3;
  183.         upFont= Nlm_FontHeight();
  184.         rowtop= r.top + kIndexRise;
  185.         }
  186.     Nlm_MoveTo( cleft, rowtop);
  187.     Nlm_LineTo( r.right, rowtop);
  188.     
  189.     cleft += fItemWidth / 2; // add a bit to put tics over bases
  190.     for (long at= startitem; at <= stopitem; at++, cleft += fItemWidth) {
  191.         atx= cleft;
  192.         aty= rowtop;
  193.         Nlm_MoveTo( atx, aty);
  194.         if (at % 10 == 4) {
  195.             char  nums[128];
  196.             sprintf(nums, "%d", at+1);  
  197.             short ws= Nlm_StringWidth(nums);
  198.             aty += up1;
  199.             Nlm_LineTo(atx, aty);
  200.             aty += upFont;
  201.             atx -= ws/2;
  202.             Nlm_MoveTo( atx, aty);
  203.             Nlm_PaintString(nums);
  204.             }        
  205.         else {
  206.           aty += up2;
  207.             Nlm_LineTo(atx, aty);
  208.             }
  209.         }
  210. }
  211.     
  212. const char*  DDrawIndexRow::Write( short row, short col, long startitem, long stopitem)
  213.     long len, i, at;
  214.     char    * numline, * ticline, *cp;
  215.     
  216.     len= Min( kMaxLinebuf / 2, stopitem-startitem);
  217.     Nlm_MemFill( fLinebuf, ' ', (len + 1)*2);
  218.     if (fIsUp) {
  219.       numline= fLinebuf;
  220.         ticline= fLinebuf + len + 1;
  221.         }
  222.     else {
  223.       ticline= fLinebuf;
  224.         numline= fLinebuf + len + 1;
  225.         }
  226.     
  227.     for (i= 0, at=startitem; i < len; i++, at++) {
  228.         if (at % 10 == 4) {
  229.             char nums[128];
  230.             short  ws;
  231.             ticline[i]= '+';
  232.           sprintf(nums, "%d", at+1);
  233.           ws= StrLen(nums);
  234.           cp= numline + i - ws / 2;
  235.           MemCpy( cp, nums, ws);
  236.             }
  237.         //else if (fIsUp) ticline[i]= '_'; 
  238.         else 
  239.             ticline[i]= '-';
  240.         }
  241.  
  242.         fLinebuf[len]= '\n'; // newline !?
  243.         len= 2*len + 1;
  244.         fLinebuf[len]= 0;
  245.         return fLinebuf;
  246. }
  247.     
  248.     
  249.  
  250. // class DDrawSeqRow
  251.  
  252. DDrawSeqRow::DDrawSeqRow(Nlm_FonT itsFont, DSeqPrintView* itsView, DSequence* itsSeq,
  253.                                                      DList* itsStyles, char* name, ulong* colors) : 
  254.         fView(itsView), fColors(colors), 
  255.         fSeq(itsSeq), fTopSeq(NULL), fBotSeq(NULL),
  256.         fStyles( itsStyles), 
  257.         fFirstcommon(NULL), fCommonbase(NULL),
  258.         fBases(NULL), fLength(0)
  259. {  
  260.     if (fSeq) {
  261.         fBases= fSeq->Bases();
  262.         fLength= fSeq->LengthF();
  263.         }
  264.     fFont= itsFont; 
  265.     if (name) StrNCpy( fNameStore, name, sizeof(fNameStore)); 
  266.     else *fNameStore= 0;
  267.     fName= fNameStore; 
  268.     if (fFont) Nlm_SelectFont(fFont);
  269.     fHeight= BaseLineHeight();
  270.     fItemWidth= BaseCharWidth();
  271. }
  272.  
  273.  
  274. DSeqStyle* DDrawSeqRow::GetStyle(long ibase, short masklevel, DSequence* aSeq)
  275. {
  276.     short maskval= 0;
  277.     if (aSeq) maskval= aSeq->MaskAt(ibase, masklevel);
  278.     if (maskval>0)  
  279.         return (DSeqStyle*) fStyles->At(masklevel-1);
  280.     else
  281.         return NULL;
  282. }
  283.  
  284.  
  285. void DDrawSeqRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  286. {
  287.     enum patvals { kNoPat, kHasFillPat, kHasFramePat };
  288.     char* bases= fBases;
  289.     if (bases && startitem < fLength) {
  290.     char    ch, lastch, *b;
  291.     short    atx, aty, masklevel, maskval;
  292.     long    ibase;
  293.     ulong    newcolor, curcolor, blackcolor;
  294.     patvals  haspat= kNoPat;
  295.          DSeqStyle * style, * laststyle, * nextstyle, * topstyle, * botstyle;
  296.    
  297.         if (col>0) {
  298.             bases += col; 
  299.             startitem += col;
  300.             }
  301.         if (stopitem > fLength) stopitem= fLength;
  302.         long len= stopitem - startitem;
  303.         atx= r.left;
  304.         aty= r.bottom - 2;
  305.         
  306.         if (fFont) Nlm_SelectFont(fFont);
  307.         Nlm_Black();
  308.         Nlm_TextTransparent();
  309.         curcolor= blackcolor= Nlm_GetColor();
  310.         
  311. #if MASKS
  312.         topstyle= botstyle= NULL;
  313.         laststyle= nextstyle= NULL;
  314.         if (startitem>0) 
  315.          for (masklevel=1; masklevel<5; masklevel++) {
  316.             laststyle= GetStyle( startitem-1, masklevel, fSeq);
  317.             if (laststyle) break;
  318.             }
  319. #endif
  320.             
  321.         lastch= 0;
  322.         for (b= bases + startitem, ibase=startitem; *b && ibase<stopitem; b++, ibase++) {
  323.             Nlm_MoveTo( atx, aty);
  324.             ch= *b;
  325.             if (ch == DSequence::indelSoft) ch= DSequence::indelHard; //looks better for output...
  326.     
  327. #if MASKS
  328.             Boolean needdraw= true;
  329.             Nlm_RecT crec;
  330.             maskval= fSeq->MaskAt(ibase,0); // val for all masks
  331.             if (maskval>0) 
  332.              for (masklevel=1; needdraw && masklevel<5; masklevel++) {
  333.                     // LATER: want to allow drawing of all mask forms for each base !?
  334.                 style= GetStyle( ibase, masklevel, fSeq);
  335.                 if (style) {
  336.                     Nlm_LoadRect( &crec, atx, r.top, atx+fItemWidth, r.bottom);
  337.                     nextstyle= GetStyle( ibase+1, masklevel, fSeq);
  338.                     topstyle= GetStyle( ibase, masklevel, fTopSeq);
  339.                     botstyle= GetStyle( ibase, masklevel, fBotSeq);
  340.  
  341. #if 1
  342.                     if (style->repeatchar && fItemrow > 0 
  343.                         && fCommonbase && fFirstcommon
  344.                         && fCommonbase[ibase] != '!'
  345.                         && fItemrow > (unsigned char)fFirstcommon[ibase]
  346.                         && toupper(ch) == fCommonbase[ibase]) 
  347.                           ch= style->repeatchar;
  348. #else                    
  349.                     if (style->repeatchar && fItemrow > 0 
  350.                         && DStyleTable::fToprow 
  351.                         && ibase < DStyleTable::fToprowlen 
  352.                         && ch == DStyleTable::fToprow[ibase]) 
  353.                           ch= style->repeatchar;
  354. #endif
  355.                           
  356.                     if (style->uppercase) ch= toupper(ch);
  357.                     else if (style->lowercase) ch= tolower(ch);
  358.                     
  359.                     if (style->font && 
  360.                     (style->font != Nlm_fontInUse || style->font != DStyleTable::fLaststyle.font)) 
  361.                           Nlm_SelectFont(style->font);
  362.                          
  363.                         // this is good only w/ backcolor !?
  364.                      if (style->dofontpat) { 
  365.                         if ( haspat == kHasFillPat || 
  366.                          (Nlm_MemCmp(style->fontpattern, DStyleTable::fLaststyle.fontpattern, 8) != 0)
  367.                          ) {
  368.                              Nlm_PenPattern(style->fontpattern);  
  369.                              haspat= kHasFillPat;
  370.                              }
  371.                          }
  372.                      else if (haspat) { Nlm_Solid(); haspat= kNoPat; }
  373.                              
  374.                     if (style->dobackcolor) { 
  375.                         newcolor= style->backcolor;
  376.                         if (curcolor != newcolor) {
  377.                             curcolor= newcolor;
  378.                             Nlm_SetColor( curcolor);  
  379.                             }
  380.                         Nlm_PaintRect(&crec);
  381.                         }  
  382.  
  383.                     if (style->dofontcolor) newcolor= style->fontcolor;
  384.                     else if (fColors) newcolor= fColors[ch-' '];
  385.                     else newcolor= blackcolor;  
  386.                     if (curcolor != newcolor) {
  387.                         curcolor= newcolor;
  388.                         Nlm_SetColor( curcolor);  
  389.                         }
  390.  
  391.                     //if (style->invertcolor) Nlm_InvertColors();
  392.                     //if (style->invertcolor) Nlm_EraseMode();//TextMode(srcBIC);
  393.                     
  394.                     BaseDraw(ch);
  395.                     needdraw= false;
  396.  
  397.                     //if (style->invertcolor) Nlm_CopyMode();
  398.                     if (style->invertcolor) Nlm_InvertRect( &crec);
  399.                     
  400.                     if (style->frame) { 
  401.                         Boolean anyframe, leftframe, rightframe, topframe, botframe;
  402.                         leftframe = (!(laststyle && laststyle->frame));
  403.                         rightframe= (!(nextstyle && nextstyle->frame));
  404.                         topframe  = (!(topstyle && topstyle->frame));
  405.                         botframe  = (!(botstyle && botstyle->frame));
  406.                         anyframe  = leftframe||rightframe||topframe||botframe;
  407.                         
  408.                         if (anyframe) { 
  409.                           if (style->doframecolor) newcolor= style->framecolor;
  410.                             else newcolor= blackcolor; 
  411.                             if (curcolor != newcolor) {
  412.                                 curcolor= newcolor;
  413.                                 Nlm_SetColor( curcolor);  
  414.                                 }
  415.                              if (style->framestyle) { 
  416.                                  switch (style->framestyle) {
  417.                                      case DSeqStyle::kFrameSolid : Nlm_Solid(); break;
  418.                                      case DSeqStyle::kFrameDark  : Nlm_Dark(); break;
  419.                                      case DSeqStyle::kFrameMedium: Nlm_Medium(); break;
  420.                                      case DSeqStyle::kFrameLight : Nlm_Light(); break;
  421.                                      case DSeqStyle::kFrameDotted: Nlm_Dotted(); break;
  422.                                      case DSeqStyle::kFrameDashed: Nlm_Dashed(); break;
  423.                                      }
  424.                                  }
  425.                              haspat= kHasFramePat;
  426.                             }
  427.  
  428.                         if (leftframe) { 
  429.                             Nlm_MoveTo(crec.left,crec.top); 
  430.                             Nlm_LineTo(crec.left,crec.bottom); 
  431.                             } 
  432.                         if (rightframe) { 
  433.                             Nlm_MoveTo(crec.right-1,crec.top); 
  434.                             Nlm_LineTo(crec.right-1,crec.bottom); 
  435.                             } 
  436.                         if (topframe) { 
  437.                             Nlm_MoveTo(crec.left,crec.top); 
  438.                             Nlm_LineTo(crec.right,crec.top); 
  439.                             } 
  440.                         if (botframe) { 
  441.                             Nlm_MoveTo(crec.left,crec.bottom-1); 
  442.                             Nlm_LineTo(crec.right,crec.bottom-1); 
  443.                             } 
  444.                         if (anyframe) Nlm_TextTransparent(); // MSWin LineTo/DrawLine resets Opaque!
  445.                         }
  446.  
  447.                     DStyleTable::fLaststyle= *style;
  448.                     laststyle= style;
  449.                     }
  450.                 }
  451.             
  452.             if (needdraw) {
  453.                 if (haspat) { Nlm_Solid(); haspat= kNoPat; }
  454.                  if (Nlm_fontInUse != fFont) Nlm_SelectFont(fFont); 
  455.                 if (fColors) {
  456.                     newcolor= fColors[ch-' '];
  457.                     if (curcolor != newcolor) {
  458.                         curcolor= newcolor;
  459.                         Nlm_SetColor( curcolor);  
  460.                         }
  461.                     }
  462.                 else if (curcolor != blackcolor) {
  463.                     Nlm_Black(); // if WithStyle left a color set.... !!
  464.                     curcolor= blackcolor;
  465.                     }
  466.                 BaseDraw(ch);
  467.                 laststyle= NULL;
  468.                 }
  469.  
  470. #else
  471.              if (fColors) {
  472.                  // if (swapBackcolor) Nlm_SetBackColor( fColors[ch-' ']); else 
  473.                 if (ch!=lastch) Nlm_SetColor( fColors[ch-' ']);
  474.                 }
  475.             BaseDraw(ch);
  476. #endif
  477.             lastch= ch;
  478.             atx += fItemWidth;   
  479.             }    
  480.         Nlm_TextOpaque();
  481.         Nlm_Black();
  482.         if (haspat) { Nlm_Solid(); haspat= kNoPat; }
  483.         curcolor= blackcolor;
  484.         }
  485. }
  486.  
  487. const char* DDrawSeqRow::Write( short row, short col, long startitem, long stopitem)
  488.     long  len, i;
  489.     char* bases= fBases;
  490.     len= Min( kMaxLinebuf, stopitem-startitem);
  491.     if (bases && startitem < fLength) {
  492.     char    ch, *b;
  493.         if (stopitem > fLength) stopitem= fLength;        
  494.         for (b= bases + startitem, i=0; *b && i<len; b++, i++) {
  495.             ch= *b;
  496.             if (ch == DSequence::indelSoft) ch= DSequence::indelHard; //looks better
  497.             fLinebuf[i]= ch;
  498.             }    
  499.         for ( ; i<len; i++) fLinebuf[i]= ' ';
  500.         }
  501.     fLinebuf[len]= 0;
  502.     return fLinebuf;
  503. }
  504.     
  505.     
  506.  
  507. // class DDrawManySeqRow
  508.  
  509.  
  510.  
  511. DDrawManySeqRow::DDrawManySeqRow(Nlm_FonT itsFont, DSeqPrintView* itsView, 
  512.                                             DSeqList* seqlist, long seqIndex, DList* itsStyles, ulong* colors,
  513.                                             char* commonbases, char* firstcommon) : 
  514.       DDrawSeqRow( itsFont, itsView, NULL, itsStyles, NULL, colors),
  515.         fSeqList(seqlist)
  516. {
  517.     fItemrow= seqIndex;
  518.     fSeq= seqlist->SeqAt( fItemrow);
  519.     if (fSeq) {
  520.         StrNCpy( fNameStore, fSeq->Name(), sizeof(fNameStore));
  521.         fName= fNameStore;
  522.         fBases= fSeq->Bases();
  523.         fLength= fSeq->LengthF();
  524.         }
  525.     fTopSeq= seqlist->SeqAt(fItemrow-1);
  526.     fBotSeq= seqlist->SeqAt(fItemrow+1);
  527.     fCommonbase= commonbases;
  528.     fFirstcommon= firstcommon;
  529.     //fCommonbase= fSeqList->FindCommonBases(DSeqList::gMinCommonPercent, fFirstcommon);
  530. }
  531.  
  532. #if 0
  533. DDrawManySeqRow::~DDrawManySeqRow()
  534. {
  535. }
  536.  
  537. char* DDrawManySeqRow::GetName(short row)
  538. {
  539.     //DSequence* aSeq= NULL;
  540.     //short atseq= (row % fLinesPerparag) - fTopPerparag;
  541.     //if (fItemrow>=0) aSeq= (DSequence*) fSeqList->At( fItemrow);
  542.     //if (fSeq) return fSeq->Name(); else 
  543.     return fName;
  544. }
  545.  
  546. void DDrawManySeqRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  547. {
  548.     //DSequence* aSeq= NULL;
  549. //    short atseq= (row % fLinesPerparag) - fTopPerparag; // == fItemrow
  550.     //if (fItemrow>=0) aSeq= (DSequence*) fSeqList->At(fItemrow);
  551.     if (fSeq) {
  552.         //fSeq= aSeq;
  553.         //fTopSeq= (DSequence*) fSeqList->At(fItemrow-1);
  554.         //fBotSeq= (DSequence*) fSeqList->At(fItemrow+1);
  555.         //fBases= aSeq->Bases();
  556.         //fLength= aSeq->LengthF();
  557.       DDrawSeqRow::Draw( r, row, col, startitem, stopitem);
  558.         }
  559. }
  560.  
  561. const char* DDrawManySeqRow::Write( short row, short col, long startitem, long stopitem)
  562.     //DSequence* aSeq= NULL;
  563. //    short atseq= (row % fLinesPerparag) - fTopPerparag;
  564.     //if (fItemrow>=0) aSeq= (DSequence*) fSeqList->At(fItemrow);
  565.     if (fSeq) {
  566.         //fSeq= aSeq;
  567.         //fBases= aSeq->Bases();
  568.         //fLength= aSeq->LengthF();
  569.       return DDrawSeqRow::Write( row, col, startitem, stopitem);
  570.         }
  571.     else
  572.         return "";
  573. }
  574.  
  575. #endif
  576.  
  577.  
  578.  
  579. // class DDrawAminoRow
  580.  
  581.  
  582. DDrawAminoRow::DDrawAminoRow(Nlm_FonT itsFont, DSequence* itsSeq, short frame) : 
  583.         fAAseq(NULL), fFrame( frame), fLength(0), 
  584.         fOnlyORF(DSeqPrintPrefs::gOnlyORF),
  585.         fThreeLet(DSeqPrintPrefs::gThreeLetAA) 
  586. {
  587.     Boolean iscomp = frame > 2;
  588.     short   offset = frame % 3;
  589.     fFont= itsFont;
  590.     if (fFont) Nlm_SelectFont(fFont);
  591.     fHeight= BaseLineHeight();
  592.     fItemWidth= BaseCharWidth();
  593.     sprintf( fNameStore, "aa%d", frame);
  594.     fName= fNameStore;
  595.     if (iscomp) {
  596.         itsSeq->SetSelection( -1,-1);
  597.         itsSeq= itsSeq->Reverse();
  598.             // strange patches...
  599.         if (offset==1) offset= 2;     
  600.         else if (offset==2) offset= 1; 
  601.         if (offset==2) itsSeq->InsertSpacers(itsSeq->LengthF(),offset,'?');   
  602.         }
  603.     itsSeq->SetSelection( offset, itsSeq->LengthF() - offset);
  604.     fAAseq= itsSeq->Translate(false);
  605.     if (iscomp) { delete itsSeq; itsSeq= NULL; }
  606.     if (fAAseq) {
  607.         fBases= fAAseq->Bases();
  608.         fLength= fAAseq->LengthF();
  609.         if (fOnlyORF) {
  610.             long    i;
  611.             Boolean isorf;
  612.             char startamino= DCodons::startamino();
  613.             for (isorf= true, i= 0; i<fLength; i++) {
  614.                 if (isorf) {
  615.                   if (fBases[i] == '*') isorf= false;
  616.                   }
  617.                 else {
  618.                      if (fBases[i] == startamino) isorf= true;
  619.                      if (!isorf) fBases[i]= ' ';
  620.                     }
  621.                 }
  622.             }
  623.         if (iscomp) { 
  624.             fAAseq->SetSelection( -1,-1);
  625.             DSequence* unrevAA= fAAseq->Reverse(); 
  626.             delete fAAseq; 
  627.             fAAseq= unrevAA; 
  628.             fBases= fAAseq->Bases();
  629.             fLength= fAAseq->LengthF();
  630.             }
  631.         }
  632. }
  633.  
  634. void DDrawAminoRow::Draw( Nlm_RecT& r, short row, short col, long startitem, long stopitem)
  635. {
  636.     long   len;
  637.     short  leftindent;
  638.     char*  bases= fBases;
  639.     if (bases) {
  640.         if (col) {
  641.             bases += col; 
  642.             startitem += col;
  643.             }
  644. #if 0
  645.       short indents[3,3] = {
  646.                           {0,1,2},
  647.                                                 {2,0,1},
  648.                                               {1,2,0}
  649.                                                 };
  650.         // at   0 -> 0,1,2 now & want          0%3=0
  651.         // at  50 -> 2,0,1 now -> 1,2,0 want  50%3=2
  652.         // at 100 -> 1,2,0 now -> 2,0,1 want 100%3=1
  653.         // at 150 -> 0,1,2 now & want        150%3=0
  654. #endif
  655.         leftindent=  (fFrame + (3 - (startitem % 3)) % 3) % 3; 
  656.         
  657.         len= (stopitem - startitem + 2) / 3;
  658.         startitem = (startitem + 2) / 3;  // adjust for 3-to-1 NA-to-AA translate
  659.         if (startitem + len > fLength) len= fLength - startitem;
  660.         if (startitem < fLength) {
  661.         char     *b;
  662.         short  chleft, chvert, chwidth;
  663.             
  664.             chvert= r.bottom-2;
  665.             chwidth = fItemWidth; 
  666.             chleft = r.left + chwidth * leftindent;    
  667.             chwidth *= 3;    
  668.             if (fFont) Nlm_SelectFont(fFont);
  669.             if (fThreeLet) for (b= bases+startitem; *b && len; b++, len--) {
  670.                 Nlm_MoveTo( chleft, chvert);
  671.                 Nlm_PaintString( (char*) DSequence::Amino123(*b));
  672.                 chleft += chwidth;
  673.                 }
  674.             else for (b= bases+startitem; *b && len; b++, len--) {
  675.                 Nlm_MoveTo( chleft, chvert);
  676.                 BaseDraw(*b);
  677.                 chleft += chwidth;
  678.                 }        
  679.             }
  680.         }
  681. }
  682.  
  683. const char* DDrawAminoRow::Write( short row, short col, long startitem, long stopitem)
  684.     long   len, alen;
  685.     short  leftindent;
  686.     char*  bases= fBases;
  687.     if (bases) {
  688.         len= Min( kMaxLinebuf, 1+stopitem-startitem);
  689.         Nlm_MemFill( fLinebuf, ' ', len);
  690.         
  691.         leftindent=  (fFrame + (3 - (startitem % 3)) % 3) % 3; 
  692.         
  693.         alen= (stopitem - startitem + 2) / 3;
  694.         startitem = (startitem + 2) / 3;  // adjust for 3-to-1 NA-to-AA translate
  695.         if (startitem + alen > fLength) alen= fLength - startitem;
  696.         if (startitem < fLength) {
  697.         char    *b, *cp;
  698.         long    i;
  699.             i= leftindent;    
  700.             if (fThreeLet) 
  701.              for (b= bases+startitem; *b && alen && i<len; b++, alen--, i += 3) {
  702.                 char * amino3= (char*) DSequence::Amino123(*b);
  703.                 cp= fLinebuf + i;
  704.                 MemCpy( cp, amino3, 3);
  705.                 }
  706.             else 
  707.              for (b= bases+startitem; *b && alen && i<len; b++, alen--, i += 3) {
  708.                 fLinebuf[i]= *b;
  709.                 }        
  710.             }
  711.         }
  712.     fLinebuf[len]= 0;
  713.     return fLinebuf;
  714. }
  715.     
  716.  
  717.  
  718.  
  719.  
  720.  
  721. /******** 
  722. methods & fields for various draw objects:
  723.   single-seq
  724.   multi-seq  
  725.     single-seq [+rezymes] [+complement] [+amino-trans] [+... others]
  726.   multi-seq  [+?consensus] [+?? annotations of various kinds for mseq ] 
  727.   
  728.   fSeqsPerParag
  729.   fSeqLinesPerParag
  730.   fSpacersPerParag
  731.   
  732.   DRowDrawer* GetRowDrawer( atseq):
  733.         Spacer, TopIndex, 
  734.         SeqLine(s), ComplSeqLine,
  735.          AA[1-3], CompAA[1-3], RestEnzyme
  736.   
  737.   make fRowsList [1..fLinesPerParag] of DRowDrawer objects...
  738.   
  739.   calcs:
  740.     //linesPerParag = fSeqLinesPerParag + fSpacersPerParag
  741.     atseq  = (row % fLinesPerParag)
  742.         seqline= (row / fLinesPerParag) * seqsperparag;  
  743.         startcol= seqline * fBasesPerLine;
  744.         stopcol = startcol + fBasesPerLine;
  745. *****/
  746.  
  747.  
  748.  
  749.  
  750.  
  751. // class DSeqPrintView
  752.  
  753.  
  754.  
  755. DSeqPrintView::DSeqPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  756.                                  DSeqList* itsSeqList, long firstbase, long nbases,
  757.                                  long pixwidth, long pixheight):
  758.     DTableView( id, itsSuper, pixwidth, pixheight, 0, 0,  
  759.                             Nlm_stdCharWidth, Nlm_stdLineHeight, true, true),
  760.     fDoc(itsDocument), fSeqList(itsSeqList), fSeq(NULL), 
  761.     fDrawRowList(NULL), fStyles(NULL),
  762.     fCommonbase(NULL), fFirstcommon(NULL),
  763.     fFirstBase(firstbase), fNbases(nbases), fMaxbases(nbases),
  764.     fSeqLinesPerParag(kSeqLinesPerParag), fTopPerparag(2),
  765.     fLinesPerParag(kSeqLinesPerParag+2), fSeqWidth(0),
  766.     fBasesPerLine(DSeqPrintPrefs::gBasesPerLine), fExtrarows(0),
  767.     fIndexWidth(kIndexWidth), fIndexWidthCnt(5),
  768.     fNameWidth(kNameWidth), fNameWidthCnt(8)
  769.  
  770.         // testing reduced view
  771.     if (gKeys->shift()) gBaseCharWidth= 1;    else gBaseCharWidth= 12; 
  772.  
  773.     this->SetSlateBorder( false);
  774.     this->SetResize( DView::relsuper, DView::relsuper);
  775.     this->SetTableFont(gTextFont);
  776.     fBaseWidth= BaseCharWidth();
  777.     fOneseq= fSeqList->GetSize()<2; 
  778.     
  779.   fSeq= (DSequence*) fSeqList->At(0);
  780.  
  781.     Initialize();  
  782. }
  783.  
  784.  
  785. void DSeqPrintView::FreeLists()
  786. {
  787.     short i, n;
  788.     if (fDrawRowList) {
  789.         n= fDrawRowList->GetSize();
  790.         for (i=0; i<n; i++) {
  791.             DDrawMapRow    *    arow= (DDrawMapRow*) fDrawRowList->At(i);
  792.             delete arow;
  793.             }
  794.         delete fDrawRowList;
  795.         }
  796.     if (fStyles) {
  797.         n= DStyleTable::fStyles->GetSize();
  798.         for (i=0; i<n; i++) {
  799.             DSeqStyle    *    astyle= (DSeqStyle*) DStyleTable::fStyles->At(i);
  800.             delete astyle;
  801.             }
  802.         delete fStyles;
  803.         }
  804. }
  805.  
  806. DSeqPrintView::~DSeqPrintView()
  807. {    
  808.     //fDrawRowList= FreeListIfObject(fDrawRowList);
  809.     //fStyles= FreeListIfObject(fStyles);
  810.     FreeLists();
  811.     MemFree( fCommonbase);
  812.     MemFree( fFirstcommon);
  813. }
  814.  
  815. void DSeqPrintView::Initialize()
  816.     fDoTopIndex= DSeqPrintPrefs::gIndexTop;
  817.     fDoLeftIndex= DSeqPrintPrefs::gIndexLeft; 
  818.     fDoRightIndex= DSeqPrintPrefs::gIndexRight;  
  819.     fDoLeftName= DSeqPrintPrefs::gNameLeft; 
  820.     fDoRightName= DSeqPrintPrefs::gNameRight;
  821.     
  822.     fNameFont = DSeqPrintPrefs::gNameFont;
  823.     fNumFont  = DSeqPrintPrefs::gIndexFont;
  824.     fBaseFont = DSeqPrintPrefs::gBaseFont;
  825. }
  826.  
  827.  
  828. void DSeqPrintView::MakeDrawList()
  829. {
  830.     short i, n;
  831.  
  832.     FreeLists();
  833.     //fDrawRowList= FreeListIfObject(fDrawRowList);
  834.     fDrawRowList= new DList(); // NULL, DList::kDeleteObjects << bad, doesn't call destruct
  835.     fDrawRowList->InsertLast( new DDrawSpacer());
  836.     if (fDoTopIndex) 
  837.         fDrawRowList->InsertLast( new DDrawIndexRow(fNumFont,fBaseWidth));
  838.  
  839.     ulong * colors;
  840.     //if (!fDoc->fUseColor) colors= NULL;
  841.     if (!DSeqPrintPrefs::gColored) colors= NULL;
  842.     else if (fSeq->Kind() == DSequence::kAmino) colors= DBaseColors::gAAcolors;
  843.     else colors= DBaseColors::gNAcolors;
  844.  
  845.     //fStyles= FreeListIfObject(fStyles);
  846.     fStyles= new DList(); // NULL,DList::kDeleteObjects << bad
  847.     n= DStyleTable::fStyles->GetSize();
  848.     for (i=0; i<n; i++) {
  849.         DSeqStyle    *    astyle= (DSeqStyle*) DStyleTable::fStyles->At(i);
  850.         astyle= (DSeqStyle*) astyle->Clone();
  851.         fStyles->InsertLast( astyle);
  852.         }
  853.         
  854.     if (!fOneseq) {
  855.         fCommonbase= fSeqList->FindCommonBases(DSeqList::gMinCommonPercent, fFirstcommon);
  856.         for (i= 0; i < fSeqLinesPerParag; i++) {
  857.           DDrawManySeqRow* dd= new DDrawManySeqRow( fBaseFont, this, fSeqList, i, 
  858.                   fStyles, colors, fCommonbase, fFirstcommon);
  859.           fDrawRowList->InsertLast(dd);
  860.             }
  861.         }
  862.     else {
  863.       for (i= 0; i < fSeqLinesPerParag; i++) { 
  864.             DDrawSeqRow* dd= new DDrawSeqRow( fBaseFont, this, fSeq, fStyles, fSeq->Name(), colors);
  865.           fDrawRowList->InsertLast( dd);
  866.            }    
  867.     }
  868. }
  869.  
  870.  
  871. void DSeqPrintView::GetReadyToShow()
  872. {
  873.     char nums[50];
  874.     long diff, nrows, nbases= 0;
  875.  
  876.     if (fOneseq)    {
  877.         fSeqsperparag = fSeqLinesPerParag;
  878.         }
  879.   else {
  880.         fSeqLinesPerParag= fSeqList->GetSize(); //?? or leave to subclasses?
  881.         fSeqsperparag = 1;
  882.         }
  883.     /* if (dospacer) */ fLinesPerParag = 1; fTopPerparag= 1;
  884.     if (fDoTopIndex) { fLinesPerParag++; fTopPerparag++; }
  885.     fLinesPerParag += fSeqLinesPerParag;
  886.  
  887. #if 1
  888.     if (fNbases) nbases= fNbases;
  889.     else
  890. #endif
  891.     if (fSeqList) {
  892.         short i, nseq= fSeqList->GetSize();
  893.         for (i=0; i<nseq; i++) {
  894.             DSequence* aseq= fSeqList->SeqAt(i);
  895.             nbases= Max(nbases, aseq->LengthF());
  896.             }
  897.         fNbases= nbases; 
  898.         }
  899.     else if (fSeq) { nbases= fSeq->LengthF(); fNbases= nbases; }
  900.     fMaxbases= nbases;
  901.     
  902.     // assume port is set??
  903.     SelectFont();
  904.     if (fNameFont) Nlm_SelectFont(fNameFont);  
  905.     fNameWidth= 5 + Nlm_StringWidth("Sequence");
  906.     fNameWidthCnt= 8;
  907.     
  908.     if (fNumFont) Nlm_SelectFont(fNumFont);  
  909.     sprintf( nums, "%d", fMaxbases);
  910.     fIndexWidthCnt= StrLen(nums);
  911.     fIndexWidth= 5 + fIndexWidthCnt * Nlm_CharWidth('0');
  912.  
  913.     if (fBaseFont) Nlm_SelectFont(fBaseFont);  
  914.     fBaseWidth= BaseCharWidth();  
  915.     
  916.     short ncols= fBasesPerLine + 4;
  917.     if (ncols > GetMaxCols()) ChangeColSize( -1, ncols-GetMaxCols());
  918.  
  919.   MakeDrawList();
  920.  
  921.     SetItemWidth( 0, 1, (fDoLeftName)?fNameWidth:1);
  922.     SetItemWidth( 1, 1, (fDoLeftIndex)?fIndexWidth:1);
  923.     SetItemWidth( 2, fBasesPerLine, fBaseWidth);  
  924.   fSeqWidth= fBasesPerLine * fBaseWidth; //!?!?
  925.     SetItemWidth( fBasesPerLine+2, 1, (fDoRightIndex)?fIndexWidth:1);
  926.     SetItemWidth( fBasesPerLine+3, 1, (fDoRightName)?fNameWidth:1);
  927.  
  928.     nrows= 1 + (nbases / fBasesPerLine) / fSeqsperparag;
  929.     nrows *= fLinesPerParag;
  930.     nrows += GetExtraRows();
  931.     diff  = Max( 3, nrows) - GetMaxRows();
  932.     ChangeRowSize( -1, diff);  // -1 prevents redraw..else use fMaxRows    
  933.  
  934.     Nlm_RecT  r;
  935.     ViewRect(r);
  936.     nrows= GetMaxRows();  
  937.     for (long irow=0; irow<nrows; irow++) {
  938.         long itemrow, seqline, startitem, stopitem;
  939.         IndexFromRow( irow, itemrow, seqline, startitem, stopitem);
  940.         DDrawMapRow* drawer= (DDrawMapRow*) fDrawRowList->At(itemrow);
  941.         SetItemHeight( irow, 1, 
  942.             (drawer) ? drawer->GetHeight(r, irow, startitem, stopitem) : Nlm_stdLineHeight);
  943.         }
  944.         
  945. }
  946.  
  947.  
  948. void DSeqPrintView::DrawSideIndex( Nlm_RecT& aRect, long index, long leftBorder)
  949. {
  950.     if (index != DDrawMapRow::kNoIndex) {
  951.         char nums[128];
  952.         Nlm_SelectFont(fNumFont); 
  953.         sprintf(nums, "%d", index); // or char* nump= ltoa(index);
  954.         short atx= aRect.right - leftBorder - Nlm_StringWidth(nums);
  955.         Nlm_MoveTo( atx, aRect.bottom - kFontDescent);
  956.         Nlm_PaintString(nums);
  957.         }
  958. }
  959.  
  960. void DSeqPrintView::WriteSideIndex( long index, long leftBorder)
  961. {
  962.     char fmt[30];
  963.     if (index != DDrawMapRow::kNoIndex) {
  964.         if (leftBorder > 0) sprintf( fmt, " %%%dd",fIndexWidthCnt);
  965.         else sprintf( fmt, " %%-%dd",fIndexWidthCnt);
  966.         fprintf( fFile->fFile, fmt, index);
  967.         }
  968.     else {
  969.         sprintf( fmt, " %%%ds",fIndexWidthCnt);
  970.         fprintf( fFile->fFile, fmt, "");
  971.         }
  972. }
  973.  
  974. void DSeqPrintView::DrawName( Nlm_RecT& aRect, short rightBorder, char* name)
  975. {
  976.     if (name) {
  977.         Nlm_SelectFont(fNameFont); 
  978.         short ht= 2 * Nlm_stdLineHeight;
  979.         if (aRect.bottom - aRect.top > ht)
  980.             Nlm_MoveTo( aRect.left + rightBorder, aRect.top + ht);
  981.         else     
  982.             Nlm_MoveTo( aRect.left + rightBorder, aRect.bottom - kFontDescent);
  983.         Nlm_PaintString( name);
  984.         } 
  985. }
  986.  
  987. void DSeqPrintView::WriteName( short rightBorder, char* name)
  988. {
  989.     char fmt[30];
  990.     if (rightBorder > 0) sprintf( fmt, "  %%-%ds",fNameWidthCnt);
  991.     else sprintf( fmt, "%%%ds ",fNameWidthCnt);
  992.     if (!name) name= "";
  993.     fprintf( fFile->fFile, fmt, name);
  994. }
  995.  
  996.  
  997. void DSeqPrintView::IndexFromRow( long row, long& itemrow, long& seqline, long& startitem, long& stopitem)
  998. {
  999.     itemrow    = (row % fLinesPerParag);  
  1000.     seqline = (row / fLinesPerParag) * fSeqsperparag;   
  1001.     if (fOneseq) seqline += Max( 0, itemrow - fTopPerparag);
  1002. #if 1
  1003.     startitem = fFirstBase + seqline * fBasesPerLine;
  1004.     stopitem  = Min(startitem + fBasesPerLine, fFirstBase+fNbases);
  1005.     if (startitem>stopitem) { startitem= stopitem; }
  1006. #else
  1007.     startitem = seqline * fBasesPerLine;
  1008.     stopitem  = startitem + fBasesPerLine;
  1009. #endif
  1010. }
  1011.  
  1012.  
  1013. void DSeqPrintView::Draw()
  1014. {
  1015. #if MASKS
  1016.             // !! toprowbases should be just CONSENSUS/Common bases, not rare ones
  1017. #if 0
  1018.     short minCommonPerCent= 70;
  1019.     char * commons= FindCommonBases( minCommonPerCent); 
  1020.      // ^^ OOPs, this is made new for each draw .. bad news
  1021.     DStyleTable::StartDraw( commons, StrLen(commons));
  1022. #else
  1023.     //DSequence* aSeq= fSeqList->SeqAt(0);
  1024.     DStyleTable::StartDraw( fSeq->Bases(), fSeq->LengthF());
  1025. #endif
  1026. #endif
  1027.  
  1028.     DTableView::Draw();
  1029.     
  1030. #if MASKS
  1031.     DStyleTable::EndDraw();
  1032. #endif
  1033. }
  1034.  
  1035. void DSeqPrintView::DrawRow(Nlm_RecT r, long row)
  1036. {
  1037.     long             itemrow, seqline, startitem, stopitem;
  1038.     long         col, ncols;
  1039.     Nlm_RecT    r1, viewr;
  1040.     Nlm_RegioN     cliprgn;
  1041.     DDrawMapRow * drawer;
  1042.     
  1043.     col = GetLeft(); 
  1044.     if (fWidths && col <= fMaxCols) r.right= r.left + fWidths[col];
  1045.     else r.right= r.left + fItemWidth;
  1046.     ViewRect( viewr);
  1047.  
  1048.     IndexFromRow( row, itemrow, seqline, startitem, stopitem);
  1049.   cliprgn= Nlm_CreateRgn();
  1050.     drawer= (DDrawMapRow*) fDrawRowList->At(itemrow);
  1051.   
  1052.     if (drawer) {
  1053.         drawer->fItemrow= itemrow - fTopPerparag;// so we know which seq line in array
  1054.         while (r.left < fRect.right && col < fMaxCols) {
  1055.             if (col < 2 || col > fBasesPerLine+1) {
  1056.                         // do name & index borders
  1057.                 ncols= 1;
  1058.                 if (col == 0 && !fDoLeftName && drawer->DoLeftName()) // special case, fiddle w/ clip rgn...
  1059.                     { r.right += fItemWidth; }
  1060.                 (void) Nlm_SectRect( &r, &viewr, &r1);
  1061.                 RectRgn( cliprgn, &r1);  
  1062.                 Nlm_SectRgn( cliprgn, Nlm_updateRgn, cliprgn);
  1063.                 if ( !Nlm_EmptyRgn( cliprgn)) {
  1064.                     Nlm_ClipRgn(cliprgn);
  1065.                     r1= r;
  1066.                     if (col == 0) {
  1067.                         if (fDoLeftName || drawer->DoLeftName()) DrawName( r1, 0, drawer->GetName(row));
  1068.                         }
  1069.                     else if (col == 1) {
  1070.                         if (fDoLeftIndex) DrawSideIndex( r1, drawer->GetIndex(startitem), kNucBorder);
  1071.                         }
  1072.                     else if (col == fBasesPerLine+2) {
  1073.                         if (fDoRightIndex) DrawSideIndex( r1,  drawer->GetIndex(stopitem), 0);
  1074.                         }
  1075.                     else if (col == fBasesPerLine+3) {
  1076.                         if (fDoRightName) DrawName( r1, kNucBorder, drawer->GetName(row));        
  1077.                         }    
  1078.                     }
  1079.                 }
  1080.                 
  1081.             else if (col < fBasesPerLine+2) {
  1082.                 r.right= r.left + fSeqWidth;
  1083.                 ncols= fBasesPerLine; //stopitem - startitem;
  1084.                 (void) Nlm_SectRect( &r, &viewr, &r1);
  1085.                 RectRgn( cliprgn, &r1);  
  1086.                 Nlm_SectRgn( cliprgn, Nlm_updateRgn, cliprgn);
  1087.                 if ( !Nlm_EmptyRgn( cliprgn)) {
  1088.                     r1= r;
  1089.                     //Nlm_ClipRgn(cliprgn);
  1090.                     //drawer->fItemrow= itemrow - fTopPerparag;// so we know which seq line in array
  1091.                     drawer->Clip( r1, row, startitem, stopitem, viewr, cliprgn);
  1092.                     drawer->Draw( r1, row, col-2, startitem, stopitem);
  1093.                     }
  1094.                 }
  1095.         
  1096.           col += ncols;
  1097.             r.left= r.right;
  1098.             if (fWidths) r.right += fWidths[col];
  1099.             else r.right += fItemWidth;
  1100.             }
  1101.         }
  1102.     //Nlm_ClipRgn(Nlm_updateRgn);
  1103.     fColsDrawn= col - GetLeft();
  1104.     Nlm_ResetClip();
  1105.     Nlm_DestroyRgn(cliprgn);
  1106. }
  1107.  
  1108.  
  1109. void DSeqPrintView::WriteTo(DFile* aFile)
  1110. {
  1111.     if (aFile) {
  1112.         long irow, nrows;
  1113.         fFile= aFile;
  1114.         fFile->Open("a");
  1115.         nrows= GetMaxRows();  
  1116.         for (irow=0; irow<nrows; irow++) WriteRow( irow);
  1117.         fFile->Close();
  1118.         }
  1119. }
  1120.  
  1121. void DSeqPrintView::WriteRow(long row)
  1122. {
  1123.     long             itemrow, seqline, startitem, stopitem;
  1124.     long         col, ncols;
  1125.     DDrawMapRow * drawer;
  1126.     char * newline, * atline;
  1127.     
  1128.     IndexFromRow( row, itemrow, seqline, startitem, stopitem);
  1129.     drawer= (DDrawMapRow*) fDrawRowList->At(itemrow);
  1130.     if (!drawer) return;
  1131.     drawer->fItemrow= itemrow - fTopPerparag;// so we know which seq line in array
  1132.  
  1133.     atline= (char*) drawer->Write( row, 0, startitem, stopitem);
  1134.     while (atline) {
  1135.         newline= StrChr(atline, '\n');
  1136.         if (newline) *newline++= 0; // risky: (const char*) drawer->Write()
  1137.         
  1138.         for (col=0, ncols=1; col<fMaxCols; col += ncols) {
  1139.             if (col < 2 || col > fBasesPerLine+1) {
  1140.                         // do name & index borders
  1141.                 ncols= 1;
  1142.                 if (col == 0) {
  1143.                     if (fDoLeftName || drawer->DoLeftName()) WriteName(  0, drawer->GetName(row));
  1144.                     }
  1145.                 else if (col == 1) {
  1146.                     if (fDoLeftIndex) WriteSideIndex( drawer->GetIndex(startitem), kNucBorder);
  1147.                     }
  1148.                 else if (col == fBasesPerLine+2) {
  1149.                     if (fDoRightIndex) WriteSideIndex(  drawer->GetIndex(stopitem), 0);
  1150.                     }
  1151.                 else if (col == fBasesPerLine+3) {
  1152.                     if (fDoRightName) WriteName(  kNucBorder, drawer->GetName(row));        
  1153.                     }    
  1154.                 }
  1155.             else {
  1156.                 ncols= fBasesPerLine; 
  1157.                 fFile->WriteLine( " ", false);
  1158.                 fFile->WriteLine( atline, false);
  1159.                 }
  1160.             }
  1161.             
  1162.         atline= newline;
  1163.         fFile->WriteLine("\n");
  1164.         }
  1165. }
  1166.  
  1167.  
  1168.  
  1169.  
  1170.  
  1171.  
  1172.  
  1173.  
  1174.  
  1175. // class DSeqPrintDoc
  1176.  
  1177.  
  1178. Nlm_RecT DSeqPrintDoc::fgPrWinRect = { 0, 0, 0, 0 };
  1179.  
  1180. DSeqPrintDoc::DSeqPrintDoc( long id, DSeqDoc* itsDoc, DSeqList* itsSeqList, long firstbase, long nbases) :
  1181.         DWindow( kSeqPrintDoc, gApplication),
  1182.         fView(NULL),  
  1183.         fSeqList(itsSeqList),
  1184.         fFirstBase(firstbase), fNbases(nbases),
  1185.         //fHeadline(NULL), fFormatPop(NULL),
  1186.         //fLockButton(NULL), fColorButton(NULL), fMonoButton(NULL),
  1187.         fColorCheck(NULL), fLockCheck(NULL), 
  1188.         fUseColor(itsDoc->fUseColor)
  1189.     short width= -1, height= -1, left= -10, top= -20; // default window loc
  1190.     if (id != 0) fId= id;
  1191.     
  1192.     //gTextFont = Nlm_GetFont( "Courier", 10, false, false, false, "Fixed");
  1193.     //if (gTextFont == NULL) gTextFont= Nlm_programFont;
  1194.  
  1195.         // testing reduced view
  1196.     if (gKeys->shift()) gBaseCharWidth= 1;    else gBaseCharWidth= 12; 
  1197.  
  1198.     if (!Nlm_EmptyRect(&fgPrWinRect))  {
  1199.         left= MAX(20,fgPrWinRect.left);
  1200.         top = MAX(40,fgPrWinRect.top);
  1201.         }
  1202.     
  1203.     char * winname= NULL;
  1204.     this->InitWindow( document, width, height, left, top); //, winname); 
  1205.  
  1206.     DSequence * aSeq;
  1207.     char title[256];
  1208.     if (!fSeqList) {
  1209.         fSeqList= new DSeqList();  
  1210.         fSeqList->AddNewSeq();    // install 1 blank seq for new doc
  1211.         aSeq= NULL;
  1212.         }
  1213.     else {
  1214.       aSeq= (DSequence*) fSeqList->At(0);
  1215.         }
  1216.     if (aSeq)  
  1217.         StrCpy(title, aSeq->Name());
  1218.     else
  1219.         itsDoc->GetTitle( title, sizeof(title)); 
  1220.     DFileManager::ReplaceSuffix( title, sizeof(title), ".Print");
  1221.     SetTitle( title);
  1222. }
  1223.  
  1224.  
  1225. DSeqPrintDoc::~DSeqPrintDoc()
  1226. {
  1227.     if (fSeqList) { 
  1228.         // we don't own DSeq objects in this list !!
  1229.         //fSeqList->FreeAllObjects(); 
  1230.         fSeqList->suicide(); 
  1231.         }
  1232. }
  1233.  
  1234.  
  1235. void DSeqPrintDoc::MakeGlobalsCurrent()
  1236. {
  1237.     ViewRect( fViewrect); // get current rect...
  1238.     if (!Nlm_EmptyRect(&fViewrect)) fgPrWinRect= fViewrect;  
  1239.     //fgUseColor= fColorCheck->GetStatus();
  1240. }
  1241.  
  1242. void DSeqPrintDoc::Close()
  1243. {
  1244.     MakeGlobalsCurrent();
  1245.     DWindow::Close();
  1246. }
  1247.  
  1248. void DSeqPrintDoc::ResizeWin()
  1249. {
  1250.     DWindow::ResizeWin();
  1251.     MakeGlobalsCurrent();
  1252. }
  1253.  
  1254.  
  1255. // static
  1256. void DSeqPrintDoc::GetGlobals()
  1257. {
  1258.  
  1259.     //char* onoffs= (fgUseColor) ? "1" : "0";
  1260.     //fgUseColor= gApplication->GetPrefVal( "fgUseColor", "windows", onoffs);
  1261.     {
  1262.     char* srect = gApplication->GetPref( "fgPrWinRect", "windows", "30 40 450 220");
  1263. #if 1
  1264.         // sscanf is failing on Mac/codewar !! used to work
  1265.     if (srect) {
  1266.         char* cp= srect;
  1267.         while (*cp && isspace(*cp)) cp++;
  1268.         fgPrWinRect.left= atoi( cp);
  1269.         
  1270.         while (*cp && !isspace(*cp)) cp++;
  1271.         while (*cp && isspace(*cp)) cp++;
  1272.         fgPrWinRect.top= atoi( cp);
  1273.         
  1274.         while (*cp && !isspace(*cp)) cp++;
  1275.         while (*cp && isspace(*cp)) cp++;
  1276.         fgPrWinRect.right= atoi( cp);
  1277.         
  1278.         while (*cp && !isspace(*cp)) cp++;
  1279.         while (*cp && isspace(*cp)) cp++;
  1280.         fgPrWinRect.bottom= atoi( cp);
  1281.         }
  1282. #else
  1283.         if (srect) sscanf( srect, "%d%d%d%d", &fgPrWinRect.left, &fgPrWinRect.top, 
  1284.                                                 &fgPrWinRect.right, &fgPrWinRect.bottom);
  1285. #endif
  1286.         Nlm_MemFree(srect);
  1287.     }
  1288. }
  1289.  
  1290. // static
  1291. void DSeqPrintDoc::SaveGlobals()
  1292. {
  1293.     //gApplication->SetPref( (int) fgUseColor, "fgUseColor","windows");
  1294.     if (!Nlm_EmptyRect(&fgPrWinRect)) {
  1295.         char  srect[128];
  1296.         sprintf( srect, "%d %d %d %d", fgPrWinRect.left, fgPrWinRect.top, 
  1297.                                                         fgPrWinRect.right, fgPrWinRect.bottom);
  1298.         gApplication->SetPref( srect, "fgPrWinRect", "windows");
  1299.         }
  1300. }
  1301.  
  1302.  
  1303. void DSeqPrintDoc::Open()
  1304. {
  1305.     DView*     super;
  1306.     short width, height;
  1307.     Nlm_PoinT        nps;
  1308.     
  1309.     //if (!fSeqList) fSeqList= new DSeqList();
  1310.     if (!fView) {
  1311.         super= this;
  1312.     
  1313.         width= 450; height= 350;
  1314.         super->GetNextPosition( &nps);
  1315.         width = MAX( 40, fgPrWinRect.right - fgPrWinRect.left) - Nlm_vScrollBarWidth  - nps.x; 
  1316.         height= MAX( 60, fgPrWinRect.bottom - fgPrWinRect.top) - Nlm_hScrollBarHeight - nps.y;   
  1317.         fView= new DSeqPrintView(0,super,this,fSeqList,fFirstBase,fNbases,width,height);
  1318.         }
  1319.  
  1320.     fSaveHandler= this;  
  1321.     fPrintHandler= this;
  1322.     
  1323.     this->Select(); // for motif
  1324.     this->CalcWindowSize();
  1325.     fView->GetReadyToShow();
  1326.     
  1327.     DWindow::Open();
  1328. }
  1329.  
  1330.  
  1331.  
  1332.  
  1333. void DSeqPrintDoc::WriteTo(DFile* aFile)  
  1334. {
  1335.         // offer user choice of Text or PICT (or other? - PS) output
  1336.         // need popup choice in save-as dialog...
  1337.         
  1338.     short outform= DSeqPrintPrefs::gOutFormat;
  1339.     if (gKeys->shift()) {
  1340.         if (outform == DSeqPrintPrefs::cOutText) outform= DSeqPrintPrefs::cOutPICT;
  1341.         else outform= DSeqPrintPrefs::cOutText; 
  1342.         }
  1343.     switch (outform) {
  1344.         case DSeqPrintPrefs::cOutPICT:
  1345.             fView->WriteToPICT( aFile);
  1346.             break;
  1347.         case DSeqPrintPrefs::cOutText:
  1348.         default:
  1349.             fView->WriteTo( aFile); 
  1350.             break;
  1351.         }
  1352. }
  1353.         
  1354.  
  1355.  
  1356. void DSeqPrintDoc::Print()  
  1357. {
  1358.     fView->Print();
  1359. }
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.  
  1370.  
  1371.  
  1372. // class DAlnPrintView
  1373.  
  1374.  
  1375. DAlnPrintView::DAlnPrintView( long id, DView* itsSuper, DSeqPrintDoc* itsDocument,
  1376.                                  DSeqList* itsSeqList, long firstbase, long nbases, long pixwidth, long pixheight):
  1377.         DSeqPrintView( id, itsSuper, itsDocument, itsSeqList, firstbase, nbases, pixwidth, pixheight)
  1378.     fSeqLinesPerParag= fSeqList->GetSize();
  1379. }
  1380.  
  1381. // class DAlnPrintDoc
  1382.  
  1383. DAlnPrintDoc::DAlnPrintDoc( long id, DSeqDoc* itsDoc, DSeqList* itsSeqList, long firstbase, long nbases) :
  1384.     DSeqPrintDoc( id, itsDoc, itsSeqList, firstbase, nbases)
  1385. {
  1386.  
  1387.     short width= 450, height= 350;
  1388.     //super->GetNextPosition( &nps);
  1389.     //width = MAX( 40, fgWinRect.right - fgWinRect.left) - Nlm_vScrollBarWidth  - nps.x; 
  1390.     //height= MAX( 60, fgWinRect.bottom - fgWinRect.top) - Nlm_hScrollBarHeight - nps.y;   
  1391.     fView= new DAlnPrintView(0,this,this,fSeqList,fFirstBase,fNbases,width,height);
  1392.  
  1393.     char title[256];
  1394.     itsDoc->GetTitle( title, sizeof(title)); 
  1395.     DFileManager::ReplaceSuffix( title, sizeof(title), ".Print");
  1396.     SetTitle( title);
  1397. }
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407. //class DSeqPrintPrefs : public DWindow 
  1408.  
  1409.  
  1410.  
  1411. DSeqPrintPrefs::DSeqPrintPrefs() :
  1412.     DWindow( 0, NULL, DWindow::fixed, -10, -10, -50, -20, "SeqPrint prefs", kDontFreeOnClose),
  1413.     fNameFontMenu(NULL), fBaseFontMenu(NULL),  fIndexFontMenu(NULL),
  1414.     fNameStyleMenu(NULL), fBaseStyleMenu(NULL),  fIndexStyleMenu(NULL),
  1415.     fNameSizeSw(NULL), fBaseSizeSw(NULL),  fIndexSizeSw(NULL),
  1416.     fREMinCuts(NULL),  fREMaxCuts(NULL), fBasePerLine(NULL),
  1417.     fNeedSave(false)
  1418. {    
  1419. }
  1420.  
  1421. DSeqPrintPrefs::~DSeqPrintPrefs()
  1422. {
  1423. }
  1424.  
  1425.  
  1426. class DOutFormatPopup : public DPopupList
  1427. {
  1428. public:
  1429.     DOutFormatPopup(long id, DView* superior, short defaultFormat);
  1430.     virtual short GetValue() {
  1431.          return  DSeqPrintPrefs::cOutText + DPopupList::GetValue() - 1;
  1432.         }
  1433. };
  1434.  
  1435. DOutFormatPopup::DOutFormatPopup(long id, DView* superior, short defaultFormat) :
  1436.             DPopupList(id,superior,true)
  1437. {
  1438.     this->AddItem( "Text");
  1439.     this->AddItem( "PICT");
  1440.     this->SetValue(defaultFormat - DSeqPrintPrefs::cOutText + 1);
  1441. }
  1442.  
  1443.  
  1444. inline Nlm_FonT GetAFont( char* fname, short fsize, short fstyle)
  1445. {
  1446.     if (StrICmp(fname,"System")==0) return Nlm_systemFont;
  1447.     else if (StrICmp(fname,"Program")==0) return Nlm_programFont;
  1448.     else return Nlm_GetFont( fname, fsize, 
  1449.              fstyle & kBold, fstyle & kItalic, fstyle & kUnderline, NULL);
  1450. }
  1451.  
  1452. // static
  1453. void DSeqPrintPrefs::InitGlobals() 
  1454.  
  1455.     gNameFontName= gApplication->GetPref( "gNameFontName", "fonts", gNameFontName);
  1456.     gNameFontSize= gApplication->GetPrefVal( "gNameFontSize", "fonts", "10");
  1457.     gNameStyle= gApplication->GetPrefVal( "gNameStyle", "fonts", "0");
  1458.     gNameFont= ::GetAFont(gNameFontName,gNameFontSize, gNameStyle);
  1459.  
  1460.     gBaseFontName= gApplication->GetPref( "gBaseFontName", "fonts", gBaseFontName);
  1461.     gBaseFontSize= gApplication->GetPrefVal( "gBaseFontSize", "fonts", "10");
  1462.     gBaseStyle= gApplication->GetPrefVal( "gBaseStyle", "fonts", "0");
  1463.     gBaseFont= ::GetAFont(gBaseFontName,gBaseFontSize, gBaseStyle);
  1464.  
  1465.     gIndexFontName= gApplication->GetPref( "gIndexFontName", "fonts", gIndexFontName);
  1466.     gIndexFontSize= gApplication->GetPrefVal( "gIndexFontSize", "fonts", "9");
  1467.     gIndexStyle= gApplication->GetPrefVal( "gIndexStyle", "fonts", "0");
  1468.     gIndexFont= ::GetAFont(gIndexFontName,gIndexFontSize, gIndexStyle);
  1469.     
  1470.     gNameLeft= gApplication->GetPrefVal( "gNameLeft", "seqprint","0");
  1471.     gNameRight= gApplication->GetPrefVal( "gNameRight", "seqprint","1");
  1472.     gIndexLeft= gApplication->GetPrefVal( "gIndexLeft", "seqprint","1");
  1473.     gIndexRight= gApplication->GetPrefVal( "gIndexRight", "seqprint","0");
  1474.     gIndexTop= gApplication->GetPrefVal( "gIndexTop", "seqprint","1");
  1475.     gColored= gApplication->GetPrefVal( "gColored", "seqprint","1");
  1476.     gBasesPerLine= gApplication->GetPrefVal( "gBasesPerLine", "seqprint","60");
  1477.     short outform= gApplication->GetPrefVal( "gOutFormat", "seqprint","0");
  1478.   if (outform) gOutFormat= outform;
  1479.   
  1480.     gShowComplement= gApplication->GetPrefVal( "gShowComplement", "seqprint","1");
  1481.     gThreeLetAA= gApplication->GetPrefVal( "gThreeLetAA", "seqprint","0");
  1482.     gOnlyORF= gApplication->GetPrefVal( "gOnlyORF", "seqprint","0");
  1483.     gShowAA1= gApplication->GetPrefVal( "gShowAA1", "seqprint","0");
  1484.     gShowAA2= gApplication->GetPrefVal( "gShowAA2", "seqprint","0");
  1485.     gShowAA3= gApplication->GetPrefVal( "gShowAA3", "seqprint","0");
  1486.     gShowCompAA1= gApplication->GetPrefVal( "gShowCompAA1", "seqprint","0");
  1487.     gShowCompAA2= gApplication->GetPrefVal( "gShowCompAA2", "seqprint","0");
  1488.     gShowCompAA3= gApplication->GetPrefVal( "gShowCompAA3", "seqprint","0");
  1489.  
  1490.     gShowAllZymes= gApplication->GetPrefVal( "gShowAllZymes", "remap","0");
  1491.     gShowCutpoints= gApplication->GetPrefVal( "gShowCutpoints", "remap","0");
  1492.     gShowNoncutters= gApplication->GetPrefVal( "gShowNoncutters", "remap","0");
  1493.     gShowExcludedCutters= gApplication->GetPrefVal( "gShowExcludedCutters", "remap","0");
  1494.  
  1495.     gREMinCuts= gApplication->GetPrefVal( "gREMinCuts", "remap","1");
  1496.     gREMaxCuts= gApplication->GetPrefVal( "gREMaxCuts", "remap","999");
  1497.  
  1498. #if 0
  1499.     {
  1500.     char* srect = gApplication->GetPref( "gSeqPrintDocRect", "windows", "20 20 450 220");
  1501.         // sscanf is failing on Mac/codewar !? used to work
  1502.     if (srect) {
  1503.         char* cp= srect;
  1504.         while (*cp && isspace(*cp)) cp++;
  1505.         gSeqPrintDocRect.left= atoi( cp);
  1506.         
  1507.         while (*cp && !isspace(*cp)) cp++;
  1508.         while (*cp && isspace(*cp)) cp++;
  1509.         gSeqPrintDocRect.top= atoi( cp);
  1510.         
  1511.         while (*cp && !isspace(*cp)) cp++;
  1512.         while (*cp && isspace(*cp)) cp++;
  1513.         gSeqPrintDocRect.right= atoi( cp);
  1514.         
  1515.         while (*cp && !isspace(*cp)) cp++;
  1516.         while (*cp && isspace(*cp)) cp++;
  1517.         gSeqPrintDocRect.bottom= atoi( cp);
  1518.         }
  1519.     MemFree(srect);
  1520.     }    
  1521. #endif
  1522.  
  1523. }
  1524.  
  1525.  
  1526. //static
  1527. void DSeqPrintPrefs::SaveGlobals() 
  1528. {
  1529.     gApplication->SetPref( gNameFontName, "gNameFontName", "fonts");
  1530.     gApplication->SetPref( gNameFontSize, "gNameFontSize", "fonts");
  1531.     gApplication->SetPref( gNameStyle, "gNameStyle", "fonts");
  1532.     gApplication->SetPref( gBaseFontName, "gBaseFontName", "fonts");
  1533.     gApplication->SetPref( gBaseFontSize, "gBaseFontSize", "fonts");
  1534.     gApplication->SetPref( gBaseStyle, "gBaseStyle", "fonts");
  1535.     gApplication->SetPref( gIndexFontName, "gIndexFontName", "fonts");
  1536.     gApplication->SetPref( gIndexFontSize, "gIndexFontSize", "fonts");
  1537.     gApplication->SetPref( gIndexStyle, "gIndexStyle", "fonts");
  1538.     
  1539.     gApplication->SetPref( gNameLeft, "gNameLeft", "seqprint");
  1540.     gApplication->SetPref( gNameRight, "gNameRight", "seqprint");
  1541.     gApplication->SetPref( gIndexLeft, "gIndexLeft", "seqprint");
  1542.     gApplication->SetPref( gIndexRight, "gIndexRight", "seqprint");
  1543.     gApplication->SetPref( gIndexTop, "gIndexTop", "seqprint");
  1544.     gApplication->SetPref( gColored, "gColored", "seqprint");
  1545.     gApplication->SetPref( gBasesPerLine, "gBasesPerLine", "seqprint");
  1546.     gApplication->SetPref( gOutFormat, "gOutFormat", "seqprint");
  1547.     
  1548. // restrict map
  1549.     gApplication->SetPref( gShowComplement, "gShowComplement", "seqprint");
  1550.     gApplication->SetPref( gThreeLetAA, "gThreeLetAA", "seqprint");
  1551.     gApplication->SetPref( gOnlyORF, "gOnlyORF", "seqprint");
  1552.     
  1553.     gApplication->SetPref( gShowAA1, "gShowAA1", "seqprint");
  1554.     gApplication->SetPref( gShowAA2, "gShowAA2", "seqprint");
  1555.     gApplication->SetPref( gShowAA3, "gShowAA3", "seqprint");
  1556.     gApplication->SetPref( gShowCompAA1, "gShowCompAA1", "seqprint");
  1557.     gApplication->SetPref( gShowCompAA2, "gShowCompAA2", "seqprint");
  1558.     gApplication->SetPref( gShowCompAA3, "gShowCompAA3", "seqprint");
  1559.  
  1560. // rest. map tables
  1561.     gApplication->SetPref( gShowAllZymes, "gShowAllZymes", "remap");
  1562.     gApplication->SetPref( gShowCutpoints, "gShowCutpoints", "remap");
  1563.     gApplication->SetPref( gShowNoncutters, "gShowNoncutters", "remap");
  1564.     gApplication->SetPref( gShowExcludedCutters, "gShowExcludedCutters", "remap");
  1565.     gApplication->SetPref( gREMinCuts, "gREMinCuts", "remap");
  1566.     gApplication->SetPref( gREMaxCuts, "gREMaxCuts", "remap");
  1567.  
  1568. }
  1569.  
  1570.  
  1571.  
  1572.  
  1573. void DSeqPrintPrefs::NewFontCluster(char* title, DView* mainview,
  1574.                     DPopupMenu*& mfont, DPopupMenu*& mstyle, DSwitchBox*& swsize,
  1575.                     char* fontname, short fontstyle, short fontsize )
  1576. {    
  1577.         // Name style -- font, font size, font style
  1578.     DPopupMenu* popm;
  1579.     DSwitchBox* sw;
  1580.     DPrompt* pr;
  1581.     DView* super;
  1582.     
  1583.     super= mainview;
  1584.     super->NextSubviewBelowLeft();
  1585.  
  1586.     DCluster* maincluster= new DCluster( 0, super, 30, 10, true, NULL); //false, title);
  1587.     super= maincluster;
  1588.  
  1589.     popm= new DPopupMenu( 0, (Nlm_GrouP)super->GetNlmObject(), "Font  ");
  1590.     mfont= popm;
  1591.     popm->AddFonts();
  1592.     popm->SetFontChoice( fontname); 
  1593.     //super->NextSubviewToRight();
  1594.  
  1595.     popm= new DPopupMenu( 0, (Nlm_GrouP)super->GetNlmObject(), "Style  ");
  1596.     mstyle= popm;
  1597.     popm->AddItem( kStylePlain, "Plain", true);
  1598.     popm->AddItem( kStyleItalic, "Italic", true);
  1599.     popm->AddItem( kStyleBold, "Bold", true);
  1600.     popm->AddItem( kStyleUnderline, "Underline", true);
  1601.     popm->SetItemStatus( kStylePlain, fontstyle==0);
  1602.     popm->SetItemStatus( kStyleItalic, fontstyle & kItalic);
  1603.     popm->SetItemStatus( kStyleBold, fontstyle & kBold);
  1604.     popm->SetItemStatus( kStyleUnderline, fontstyle & kUnderline);
  1605.     //super->NextSubviewToRight();
  1606.     
  1607.     DCluster* cluster= new DCluster(0, super, 30, 10, true, NULL);
  1608.     super= cluster;
  1609.     
  1610.     pr= new DPrompt( 0, super, "font size", 0, 0, Nlm_programFont);             
  1611.     //super->NextSubviewToRight();
  1612.     super->NextSubviewBelowLeft();
  1613.     sw = new DSwitchBox(0, super, true, true);
  1614.     swsize= sw;
  1615.     sw->SetValues(fontsize,99);
  1616.     //super->NextSubviewBelowLeft();
  1617.  
  1618.     super= mainview;
  1619.     super->NextSubviewBelowLeft();
  1620. }
  1621.  
  1622.  
  1623.  
  1624.  
  1625. void DSeqPrintPrefs::Initialize() 
  1626.     DView* super;
  1627.     DPrompt* pr;
  1628.     DCheckBox* ck;
  1629.     DCluster* clu;
  1630.     char nums[128];    
  1631.     DPopupMenu* popm;
  1632.  
  1633.     super= this;
  1634.     clu= new DCluster( 0, super, 30, 10, false, "Bases");
  1635.     super= clu;
  1636.  
  1637.     NewFontCluster( "Base style", super, fBaseFontMenu, fBaseStyleMenu, fBaseSizeSw,
  1638.                             gBaseFontName, gBaseStyle, gBaseFontSize);
  1639.  
  1640.     ck= new DCheckBox(cColored, super, "Color ");
  1641.     ck->SetStatus(gColored);
  1642.     super->NextSubviewToRight();
  1643.     
  1644.     sprintf( nums, "%d", gBasesPerLine);
  1645.     fBasePerLine= new DEditText( 0, super, nums, 4, Nlm_programFont); 
  1646.     this->SetEditText( fBasePerLine);
  1647.     super->NextSubviewToRight();
  1648.     pr= new DPrompt( 0, super, "bases/line", 0, 0, Nlm_programFont);             
  1649.  
  1650.     super = this;
  1651.     //super->NextSubviewToRight();
  1652.     //super->NextSubviewBelowLeft();
  1653.  
  1654.     clu= new DCluster( 0, super, 30, 10, false, "Indices");
  1655.     super= clu;
  1656.  
  1657.     NewFontCluster( "Index style", super, fIndexFontMenu, fIndexStyleMenu, fIndexSizeSw,
  1658.                             gIndexFontName, gIndexStyle, gIndexFontSize);
  1659.  
  1660.     ck= new DCheckBox(cIndexLeft, super, "Left");
  1661.     ck->SetStatus(gIndexLeft);
  1662.     ck= new DCheckBox(cIndexRight, super, "Right");
  1663.     ck->SetStatus(gIndexRight);
  1664.     ck= new DCheckBox(cIndexTop, super, "Top");
  1665.     ck->SetStatus(gIndexTop);
  1666.  
  1667.     super = this;
  1668.     //super->NextSubviewToRight();
  1669.     //super->NextSubviewBelowLeft();
  1670.  
  1671.     clu= new DCluster( 0, super, 30, 10, false, "Names");
  1672.     super= clu;
  1673.  
  1674.     NewFontCluster( "Name style", super, fNameFontMenu, fNameStyleMenu, fNameSizeSw,
  1675.                             gNameFontName, gNameStyle, gNameFontSize);
  1676.  
  1677.     ck= new DCheckBox(cNameLeft, super, "Left");
  1678.     ck->SetStatus(gNameLeft);
  1679.     ck= new DCheckBox(cNameRight, super, "Right");
  1680.     ck->SetStatus(gNameRight);
  1681.     
  1682.     super = this;
  1683.     //super->NextSubviewToRight();
  1684.     //super->NextSubviewBelowLeft();
  1685.  
  1686.     clu= new DCluster( 0, super, 0, 0, true);
  1687.     super= clu;
  1688.     pr= new DPrompt(0,super,"File format:",0, 0, Nlm_programFont);
  1689.     super->NextSubviewToRight();
  1690.     DOutFormatPopup* apop = new DOutFormatPopup( cOutText, super, gOutFormat);
  1691.     super = this;
  1692.     super->NextSubviewBelowLeft();
  1693.  
  1694.     //super->NextSubviewToRight();
  1695.  
  1696. #if 1        
  1697.  
  1698.                 // turn this into 2nd dialog window...
  1699.                 
  1700.     clu= new DCluster( 0, super, 30, 10, false, "Restriction Maps");
  1701.     super= clu;
  1702.  
  1703.     ck= new DCheckBox(cShowComplement, super, "Show Complement");
  1704.     ck->SetStatus(gShowComplement);
  1705.     super->NextSubviewBelowLeft();
  1706.     
  1707.     DCluster* pclu= new DCluster( 0, super, 30, 10, false, "Protein translate frame");
  1708.     super= pclu;
  1709.     pr= new DPrompt( 0, super, " sequence", 0, 0, Nlm_programFont);             
  1710.     super->NextSubviewToRight();
  1711.     ck= new DCheckBox(cShowAA1, super, "1st");
  1712.     ck->SetStatus(gShowAA1);
  1713.     super->NextSubviewToRight();
  1714.     ck= new DCheckBox(cShowAA2, super, "2nd");
  1715.     ck->SetStatus(gShowAA2);
  1716.     super->NextSubviewToRight();
  1717.     ck= new DCheckBox(cShowAA3, super, "3rd");
  1718.     ck->SetStatus(gShowAA3);
  1719.     super->NextSubviewBelowLeft();
  1720.  
  1721.     pr= new DPrompt( 0, super, "complement", 0, 0, Nlm_programFont);             
  1722.     super->NextSubviewToRight();
  1723.     ck= new DCheckBox(cShowCompAA1, super, "1st");
  1724.     ck->SetStatus(gShowCompAA1);
  1725.     super->NextSubviewToRight();
  1726.     ck= new DCheckBox(cShowCompAA2, super, "2nd");
  1727.     ck->SetStatus(gShowCompAA2);
  1728.     super->NextSubviewToRight();
  1729.     ck= new DCheckBox(cShowCompAA3, super, "3rd");
  1730.     ck->SetStatus(gShowCompAA3);
  1731.  
  1732.     super->NextSubviewBelowLeft();
  1733.     ck= new DCheckBox(cThreeLetAA, super, "3-letter code");
  1734.     ck->SetStatus(gThreeLetAA);
  1735.     super->NextSubviewToRight();
  1736.     ck= new DCheckBox(cOnlyORF, super, "ORFs only");
  1737.     ck->SetStatus(gOnlyORF);
  1738.     super= clu;
  1739.     super->NextSubviewBelowLeft();
  1740.  
  1741.     DCluster* rclu= new DCluster( 0, super, 30, 10, false, "Restriction enzymes");
  1742.     super= rclu;
  1743.  
  1744.     pr= new DPrompt( 0, super, "Min. cuts", 0, 0, Nlm_programFont);             
  1745.     super->NextSubviewToRight();
  1746.     sprintf( nums, "%d", gREMinCuts);
  1747.     fREMinCuts= new DEditText( 0, super, nums, 4, Nlm_programFont); 
  1748.     this->SetEditText( fREMinCuts);
  1749.     pr= new DPrompt( 0, super, "Max. cuts", 0, 0, Nlm_programFont);             
  1750.     super->NextSubviewToRight();
  1751.     sprintf( nums, "%d", gREMaxCuts);
  1752.     fREMaxCuts= new DEditText( 0, super, nums, 4, Nlm_programFont); 
  1753.     super->NextSubviewBelowLeft();
  1754.  
  1755.     pr= new DPrompt( 0, super, "Tables", 0, 0, Nlm_programFont);             
  1756.     super->NextSubviewToRight();
  1757.     ck= new DCheckBox(cShowCutpoints, super, "Cutpoints");
  1758.     ck->SetStatus(gShowCutpoints);
  1759.     ck= new DCheckBox(cShowAllZymes, super, "All zymes");
  1760.     ck->SetStatus(gShowAllZymes);
  1761.     super->NextSubviewBelowLeft();
  1762.     ck= new DCheckBox(cShowNoncutters, super, "Noncutters");
  1763.     ck->SetStatus(gShowNoncutters);
  1764.     ck= new DCheckBox(cShowExcludedCutters, super, "Excluded cutters");
  1765.     ck->SetStatus(gShowExcludedCutters);
  1766.  
  1767.     super= clu;
  1768.  
  1769.     super= this;
  1770. #endif
  1771.  
  1772.     this->AddOkayCancelButtons();
  1773.     
  1774. }
  1775.  
  1776.  
  1777. void DSeqPrintPrefs::OkayAction() 
  1778.     short             aSize, aStyle;
  1779.     char            name[256], *nums;
  1780.     DMenu     *    aFontMenu, * aStyleMenu;
  1781.     Nlm_FonT    aFont;
  1782.     
  1783.     if (fREMinCuts) {
  1784.         nums= fREMinCuts->GetTitle(name, sizeof(name));
  1785.         gREMinCuts= atol(nums);
  1786.         }
  1787.     if (fREMaxCuts) {
  1788.         nums= fREMaxCuts->GetTitle(name, sizeof(name));
  1789.         gREMaxCuts= atol(nums);
  1790.         }
  1791.     if (fBasePerLine) {
  1792.         nums= fBasePerLine->GetTitle(name, sizeof(name));
  1793.         gBasesPerLine= atol(nums);
  1794.         }
  1795.  
  1796.         
  1797.     for (short imenu= 0; imenu<3; imenu++) {
  1798.         
  1799.         switch (imenu) {
  1800.           case 0:
  1801.                 aFontMenu= fNameFontMenu; 
  1802.                 aStyleMenu= fNameStyleMenu; 
  1803.                 aSize= fNameSizeSw->GetValue();// aSize= gNameFontSize;
  1804.               break;
  1805.           case 1:
  1806.                 aFontMenu= fBaseFontMenu; 
  1807.                 aStyleMenu= fBaseStyleMenu; 
  1808.                 aSize= fBaseSizeSw->GetValue();// aSize= gBaseFontSize;
  1809.               break;
  1810.           case 2:
  1811.                 aFontMenu= fIndexFontMenu; 
  1812.                 aStyleMenu= fIndexStyleMenu; 
  1813.                 aSize= fIndexSizeSw->GetValue();// aSize= gIndexFontSize;
  1814.               break;
  1815.           }
  1816.             
  1817.         if (aFontMenu && aFontMenu->GetFontChoice(name, sizeof(name))) {
  1818.             aStyle= 0;
  1819. #ifdef WIN_MAC
  1820.             if (!aStyleMenu->GetItemStatus(kStylePlain)) {
  1821.                 if (aStyleMenu->GetItemStatus(kStyleItalic   )) aStyle |= kItalic;
  1822.                 if (aStyleMenu->GetItemStatus(kStyleBold     )) aStyle |= kBold;
  1823.                 if (aStyleMenu->GetItemStatus(kStyleUnderline)) aStyle |= kUnderline;
  1824.                 }
  1825. #else
  1826.              short item= Nlm_GetValue(((DPopupMenu*)aStyleMenu)->fPopup);
  1827.              // ^^ same as aStyleMenu->GetValue(); //??
  1828.              switch (item) {
  1829.                  case 1: aStyle= 0; break;
  1830.                  case 2: aStyle |= kItalic; break;
  1831.                  case 3: aStyle |= kBold; break;
  1832.                  case 4: aStyle |= kUnderline; break;
  1833.         }
  1834. #endif             
  1835.             if (StringCmp(name,"System")==0) aFont= Nlm_systemFont;
  1836.             else if (StringCmp(name,"Program")==0) aFont= Nlm_programFont;
  1837.             else aFont= Nlm_GetFont( name, aSize, aStyle & kBold, 
  1838.                                                     aStyle & kItalic, aStyle & kUnderline, NULL);
  1839.             
  1840.             switch (imenu) {
  1841.               case 0: 
  1842.               if (aSize != gNameFontSize || aStyle != gNameStyle || StringCmp(name,gNameFontName)!=0) {
  1843.                     if (gNameFontName) MemFree(gNameFontName);
  1844.                     gNameFontName= StrDup(name);
  1845.                     gNameFont= aFont;
  1846.                     gNameFontSize= aSize;
  1847.                     gNameStyle= aStyle;
  1848.                     fNeedSave= true;
  1849.                     }
  1850.                   break;
  1851.                   
  1852.               case 1: 
  1853.               if (aSize != gBaseFontSize || aStyle != gBaseStyle || StringCmp(name,gBaseFontName)!=0) {
  1854.                     if (gBaseFontName) MemFree(gBaseFontName);
  1855.                     gBaseFontName= StrDup(name);
  1856.                     gBaseFont= aFont;
  1857.                     gBaseFontSize= aSize;
  1858.                     gBaseStyle= aStyle;
  1859.                     fNeedSave= true;
  1860.                     }
  1861.                   break;
  1862.                   
  1863.               case 2: 
  1864.               if (aSize != gIndexFontSize || aStyle != gBaseStyle || StringCmp(name,gIndexFontName)!=0) {
  1865.                     if (gIndexFontName) MemFree(gIndexFontName);
  1866.                     gIndexFontName= StrDup(name);
  1867.                     gIndexFont= aFont;
  1868.                     gIndexFontSize= aSize;
  1869.                     gIndexStyle= aStyle;
  1870.                     fNeedSave= true;
  1871.                     }
  1872.                   break;
  1873.               }
  1874.               
  1875.             }
  1876.         }
  1877.     
  1878. #if 0
  1879. #if 1
  1880.     // CurrentWindow gets prefs dlog window, not one we want    
  1881.     //DSeqPrintDoc* awin= (DSeqPrintDoc*) gWindowManager->CurrentWindow();
  1882.     DList* wins= gWindowManager->GetWindowList();
  1883.     if (wins) {
  1884.         short last1= wins->GetSize() - 2;
  1885.         if (last1>0) {
  1886.             DSeqPrintDoc* awin= (DSeqPrintDoc*) wins->At(last1);
  1887.             if (awin && awin->Id() == DSeqPrintDoc::kSeqPrintDoc) {
  1888.                 awin->fView->Initialize();
  1889.                 awin->fView->GetReadyToShow();
  1890.                 awin->fView->Invalidate();
  1891.                 }
  1892.             }
  1893.         }
  1894. #else    
  1895.     DList* wins= gWindowManager->GetWindowList();
  1896.     if (wins) {
  1897.         long i, nwin= wins->GetSize();
  1898.         for (i= nwin-1; i>=0; i--) {
  1899.             DSeqPrintDoc* awin= (DSeqPrintDoc*) wins->At(i);
  1900.             if (awin && awin->Id() == DSeqPrintDoc::kSeqPrintDoc) {
  1901.                 awin->fView->Initialize();
  1902.                 awin->fView->GetReadyToShow();
  1903.                 awin->fView->Invalidate();
  1904.                 break; // do only 1st we find ...
  1905.                 }
  1906.             }
  1907.         }
  1908. #endif        
  1909. #endif
  1910.  
  1911. }
  1912.  
  1913.  
  1914.  
  1915. Boolean DSeqPrintPrefs::IsMyAction(DTaskMaster* action) 
  1916. {    
  1917.     DView* aview= (DView*) action;
  1918.     
  1919.     switch (action->Id()) {
  1920.  
  1921.         case cIndexLeft : gIndexLeft= aview->GetStatus(); break;
  1922.         case cIndexRight: gIndexRight= aview->GetStatus(); break;
  1923.         case cIndexTop  : gIndexTop= aview->GetStatus(); break;
  1924.         case cNameLeft    : gNameLeft= aview->GetStatus(); break;
  1925.         case cNameRight    : gNameRight= aview->GetStatus(); break;
  1926.         case cColored        : gColored= aview->GetStatus(); break;
  1927.  
  1928.         case cShowComplement: gShowComplement= aview->GetStatus(); break;
  1929.         case cThreeLetAA    : gThreeLetAA= aview->GetStatus(); break;
  1930.         case cOnlyORF    : gOnlyORF= aview->GetStatus(); break;
  1931.         case cShowAA1    : gShowAA1= aview->GetStatus(); break;
  1932.         case cShowAA2    : gShowAA2= aview->GetStatus(); break;
  1933.         case cShowAA3    : gShowAA3= aview->GetStatus(); break;
  1934.         case cShowCompAA1    : gShowCompAA1= aview->GetStatus(); break;
  1935.         case cShowCompAA2    : gShowCompAA2= aview->GetStatus(); break;
  1936.         case cShowCompAA3    : gShowCompAA3= aview->GetStatus(); break;
  1937.         case cShowCutpoints    : gShowCutpoints= aview->GetStatus(); break;
  1938.         case cShowAllZymes    : gShowAllZymes= aview->GetStatus(); break;
  1939.         case cShowNoncutters    : gShowNoncutters= aview->GetStatus(); break;
  1940.         case cShowExcludedCutters    : gShowExcludedCutters= aview->GetStatus(); break;
  1941.         case cOutText: gOutFormat= aview->GetValue(); break;
  1942.       
  1943.         default : return DWindow::IsMyAction(action);    
  1944.         }
  1945.         
  1946.     fNeedSave= true;
  1947.     return true;
  1948. }
  1949.  
  1950.  
  1951. void DSeqPrintPrefs::Open()
  1952. {
  1953.     DWindow::Open();
  1954. }
  1955.  
  1956. void DSeqPrintPrefs::Close()
  1957. {
  1958.     if (fNeedSave) {
  1959.         DSeqPrintPrefs::SaveGlobals();
  1960.         fNeedSave= false;
  1961.         }
  1962.     DWindow::Close();
  1963. }
  1964.  
  1965.  
  1966.  
  1967.     // global calling function
  1968. void SeqPrintPrefs(short id)
  1969. {
  1970.     switch (id) {
  1971.     
  1972.         case kSeqPrintPrefInit: 
  1973.             DSeqPrintPrefs::InitGlobals(); 
  1974.             break;
  1975.     
  1976.         case kSeqPrintPrefDialog:
  1977.             if (!gSeqPrintPrefs) {
  1978.                 gSeqPrintPrefs = new DSeqPrintPrefs();
  1979.                 gSeqPrintPrefs->Initialize();
  1980.                 }
  1981.             if (gSeqPrintPrefs && gSeqPrintPrefs->PoseModally()) ;
  1982.             break;
  1983.             
  1984.         case kAlnPrintPrefDialog:
  1985.         case kREMapPrefDialog:
  1986.             break;
  1987.     }
  1988.     
  1989. }
  1990.  
  1991.  
  1992.